#!/usr/bin/env bash
set -e

TEST_PROJECT=""
LOOP_COUNT=500
POSITIONAL_ARGS=()

while [[ $# -gt 0 ]]; do
	case $1 in
		-c)
			LOOP_COUNT="$2"
			shift # past argument
			shift # past value
			;;
		*)
			if [ "${TEST_PROJECT}" == "" ]; then
				TEST_PROJECT="${1}"
			else
				POSITIONAL_ARGS+=("${1}")
			fi
			shift
			;;
	esac
done

#set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters

for i in $(seq 1 ${LOOP_COUNT}); do
	echo -e "\e[1m*** Loop ${i} (Mono) ***\e[0m"
	mono src/${TEST_PROJECT}/bin/Release/net472/${TEST_PROJECT}.exe "${POSITIONAL_ARGS[@]}"
	echo -e "\e[1m*** Loop ${i} (.NET Core) ***\e[0m"
	dotnet exec src/${TEST_PROJECT}/bin/Release/net6.0/${TEST_PROJECT}.dll "${POSITIONAL_ARGS[@]}"
done
